#If...#Endif Statement

Used to control conditional compilation.


Syntax

#If TargetBoolean [Then]

//OS specific code

[#Else]

//Other OS-specific code

[#ElseIf TargetBoolean]

//Other OS-specific code for this target platform

#Endif

PartTypeDescription
TargetBoolean Boolean constant or Boolean constant expression. Constant used to determine the operating system that will include the code that follows. The DebugBuild, RBVersion, TargetBigEndian, TargetCarbon, TargetHasGUI, TargetLinux, TargetLittleEndian, TargetMacOS, TargetMachO, TargetMacOSClassic, or TargetWin32, constants are used.


Notes

Use conditional compilation to isolate platform-specific statements such as API calls, AppleEvent routines, or console application routines that are specific to Windows, Mac OS X, or Linux. The code following the #If statement is included only in the build for that operating system. TargetMacOSClassic, and TargetCarbon are mutually exclusive subsets of TargetMacOS.

The optional #ElseIf clause enables you to use a template such as this for handling all cases:

#If TargetWin32
 //Windows specific code here
#ElseIfTargetMacOS
 //Macintosh code goes here.
#ElseIfTargetLinux
 //Linux code goes right here.
#EndIf

The TargetBoolean parameter must be either a Boolean constant or a Boolean constant expression that evaluates to True or False. For example, you can use RBVersion or RBVersionString in a boolean expression that determines the user's version of REALbasic.


Example

The following example assigns values to the (user-defined) Separator property of the App class in its Open event handler. It will be used to specify full pathnames that are correct on Windows, Macintosh and Linux.

#If TargetWin32
 Separator=""
#ElseIf TargetMacOS
 Separator=":"
#ElseIf TargetLinux
 Separator="/"
#Endif

See Also

Declare statement, AppleEvent class; DebugBuild, RBVersion, RBVersionString, TargetBigEndian, TargetCarbon, TargetHasGUI, TargetLinux, TargetLittleEndian, TargetMacOS, TargetMacOSClassic, TargetMachO, TargetWin32 constants.